package com.util.file;

import com.util.Vessel;

import java.util.Scanner;

public class Student{
    //查看个人信息
    public static void viewStudentInfo(long id){
        for (int i = 0; i < Vessel.users.size(); i++) {
            if (Vessel.users.get(i).getId() == id){
                System.out.println(Vessel.users.get(i));
                break;
            }
        }
    }
    //修改密码
    public static boolean updateSpassword(long id){
        Scanner scanner =new Scanner(System.in);
        System.out.println("请问您是否记得原密码(y/n)");
        String next = scanner.next();
        if (next.equals("y")){
            for (int i = 0; i < Vessel.users.size(); i++) {
                if (Vessel.users.get(i).getId() == id){
                    System.out.println("请输入您的原始密码");
                    String oldPassword = scanner.next();
                    if (Vessel.users.get(i).getPassword().equals(oldPassword)){
                        System.out.println("请输入您的新密码");
                        String newPassword = scanner.next();
                        Vessel.users.get(i).setPassword(newPassword);
                        return true;
                    }else{
                        System.out.println("原密码错误，请重新操作");
                        break;
                    }
                }
            }
        }else if (next.equals("n")){
            for (int i = 0; i < Vessel.users.size();i++) {
                if (Vessel.users.get(i).getId() == id){
                    System.out.println("请输入您的新密码");
                    String newPassword = scanner.next();
                    Vessel.users.get(i).setPassword(newPassword);
                    return true;
                }
            }
        }
        return false;
    }

}
